<template>
  <div class="index">
    <!-- 顶部 -->
    <div class="top"><Admin></Admin></div>
    <!-- bottom -->
    <div class="bottom">
      <div class="left"><SideNav></SideNav></div>
      <div class="right">
        <div class="content">
          <el-scrollbar style="height: 100%;">
            <!-- 当前位置 -->
            <div class="current_position">
              <p class="breadcrumb">当前位置 :</p>
              <el-breadcrumb separator="/">
                <el-breadcrumb-item class="up">订单管理</el-breadcrumb-item>
                <el-breadcrumb-item class="up"><a @click="goTo('/Orders')">自营订单</a></el-breadcrumb-item>
                <el-breadcrumb-item>订单详情</el-breadcrumb-item>
              </el-breadcrumb>
            </div>
            <!-- 用户信息 -->
            <div class="userinformation">
              <div class="title">订单详情</div>
              <!-- 商品信息 -->
              <div class="proMsg">
                <div class="title">
                  <p>设备ID</p>
                  <p>商品</p>
                  <p>单价</p>
                  <p>时长(分钟)</p>
                  <p>消费金额</p>
                </div>
                <div class="box">
                  <div class="msg">
                    <p>{{orders.deviceId}}</p>
                  </div>
                  <div class="msg">
                    <p>设备使用费</p>
                    <p>泡沫使用费</p>
                    <p>吸尘使用费</p>
                    <p>洗手使用费</p>
                    <p>清水使用费</p>
                  </div>
                  <div class="msg">
                    <p>¥{{orders.durationPrice}}</p>
                    <p>¥{{orders.foamPrice}}</p>
                    <p>¥{{orders.vacuumPrice}}</p>
                    <p>¥{{orders.washPrice}}</p>
                    <p>¥{{orders.waterPrice}}</p>
                  </div>
                  <div class="msg">
                    <p>{{orders.duration}}</p>
                    <p>{{orders.foamDuration}}</p>
                    <p>{{orders.vacuumDuration}}</p>
                    <p>{{orders.washDuration}}</p>
                    <p>{{orders.waterDuration}}</p>
                  </div>
                  <div class="msg">
                    <p>¥ {{orders.durationCost}}</p>
                    <p>¥ {{orders.foamCost}}</p>
                    <p>¥ {{orders.vacuumCost}}</p>
                    <p>¥ {{orders.washCost}}</p>
                    <p>¥ {{orders.waterCost}}</p>
                  </div>
                </div>
                <div class="money">
                  实付款:<i>{{orders.money}}</i><i>元</i>
                </div>
              </div>
              <!-- 订单信息 -->
              <div class="orderMsg">
                <div class="msg">
                  <p class="name">会员信息</p>
                  <p>会员ID:{{user.id}}</p>
                  <p>会员名:{{user.wechatNickname}}</p>
                  <p>手机号:{{user.phoneNumber}}</p>
                  <p>车牌号:{{user.licence}}</p>
                </div>
                <div class="msg">
                  <p class="name">代理信息</p>
                  <p>ID:{{agent.agentId}}</p>
                  <p>姓名:{{agent.agentName}}</p>
                  <p>设备地址:{{agent.address}}</p>
                  <p>代理电话:{{agent.agentPhone}}</p>
                </div>
                <div class="msg">
                  <p class="name">订单信息</p>
                  <p>交易号:{{orders.tradeIdReps}}</p>
                  <p v-if="orders.status==1">订单状态:使用中</p>
                  <p v-if="orders.status==2">订单状态:已完成</p>
                  <p>订单编号:{{orders.tradeIdReps}}</p>
                  <p>创建订单:{{orders.startTime}}</p>
                  <p>订单结算:{{orders.endTime}}</p>
                  <p>备注: <input type="text" v-model="orders.remark" @blur="getOrderRemark()"></p>
                </div>
              </div>
            </div>
          </el-scrollbar>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  let moment = require("moment")
  import Admin from '@/components/Admin.vue'
  import SideNav from '@/components/SideNav.vue'
  export default {
    name: 'OrdersDetails',
    components:{
      Admin,
      SideNav
    },
    data () {
      return {
        id:',',//订单id
        user:'',//会员信息
        agent:'',//代理信息
        orders:'',//订单信息
      }
    },
    mounted() {
      // 取到路由带过来的参数
      this.id= JSON.parse(JSON.stringify(this.$route.query.data));

      console.log("订单信息1:"+this.id);
      this.getOrdersDetails();
    },
    // 时间格式过滤
    filters: {
      dateForma(dataStr, pattern = 'YYYY-MM-DD HH:mm:ss') {
        return moment(dataStr).format(pattern)
      }
    },
    methods: {
      // 路由
      goTo(path) {
        this.$router.push(path);
      },
      // 获取订单详情
      getOrdersDetails(){
        this.$axios.post(this.baseURL+'order/adminOrderDetail',{
          "id": this.id,
          "requestSource":"PC"
        }).then((res)=>{
          console.log(res,"订单详情");
          this.user = res.data.data.user;
          this.agent = res.data.data.agent;
          this.orders =  res.data.data.orders;
        }).catch((err)=>{
          console.log('request fail', err);
        })
      },
      // 保存订单备注
      getOrderRemark(){
        console.log(this.orders.remark,"订单备注");
        this.$axios.post(this.baseURL+'order/adminAddOrderRemark',{
          "id":this.id,
          "remark":this.orders.remark,
          "requestSource":"PC"
        }).then((res)=>{
          console.log(res,"订单备注保存");
          if(res.data.code==1){
            this.$message({
              message: '保存成功',
              type: 'success'
            });
            this.$router.go(-1);//返回上一层
          }
        }).catch((err)=>{
          console.log('request fail', err);
        })

      },
    }
  }
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="scss">
  @import '@/assets/css/index.scss'; //这个分号一定要写，要不会报错
  @import '@/assets/css/user.scss'; //这个分号一定要写，要不会报错
  .userinformation{
    width: 100%;
    height: 100%;
    // border: #008A00 1px solid;
    box-sizing: border-box;
    background-color: #F0F0F0;
    .title{
      margin-bottom: 10px;
    }
    .proMsg{
      width: 100%;
      height: auto;
      min-height: 100px;
      background-color: #FFFFFF;
      margin-bottom: 10px;
      // border: 1px solid red;
      box-sizing: border-box;
      .title{
        width: 100%;
        height: 30px;
        background-color: #95c2f3;
        padding: 0 10px;
        -webkit-box-sizing: border-box;
        box-sizing: border-box;
        line-height: 30px;
        p{
          display: inline-block;
          font-weight: bold;
          width: 19%;
          height: 100%;
          text-align: left;
        }
        p:last-child{
          text-align: right;
        }
      }
      .box{
        width: 100%;
        height: auto;
        padding: 0 10px;
        margin-bottom: 10px;
        -webkit-box-sizing: border-box;
        box-sizing: border-box;
        .msg{
          display: inline-block;
          width: 19%;
          height: 150px;
          line-height: 30px;
          vertical-align:middle;
        }
        .msg:last-child{
          text-align: right;
        }
      }
      .money{
        width: calc(100% - 20px);
        height: 50px;
        border-top: 1px solid #999999;
        margin: auto 10px;
        padding: 0 30px;
        box-sizing: border-box;
        text-align: right;
        line-height: 50px;
        font-size: 16px;
        i{
          color: #ff5733;
          font-style: normal;
          font-size: 18px;
        }
        i:last-child{
          color: #333333;
          font-size: 14px;
        }
      }
    }
    .orderMsg{
      width: 100%;
      min-height: 305px;
      background-color: #FFFFFF;
      display: flex;
      .msg{
        flex: 1;
        padding: 30px 10px 0 50px;
        .name{
          font-weight: 600;
          font-size: 18px;
        }
        p{
          line-height: 25px;
        }
        input{
          outline: none;
        }
      }
    }
  }

</style>
